<template>
  <div class="box">
    <van-datetime-picker
      v-model="currentDate"
      type="date"
      title="选择年月日"
      :min-date="minDate"
      :max-date="maxDate"
      @confirm="onConfirm"
      @cancel="onCancel"
      @change="onChange"
    />
  </div>
</template>

<script>
import { updataUser } from "@/api/user";
export default {
  name: "BirthDay",
  props: {
    userInfo: {
      required: true,
    },
  },
  data() {
    return {
      minDate: new Date(1980, 0, 1),
      maxDate: new Date(2010, 11, 31),
      currentDate: new Date(this.userInfo.birthday),
    };
  },
  methods: {
    async onConfirm(value) {
      const time = this.$dayjs(value).format("YYYY,MM,DD");

      await updataUser({
        id: this.userInfo.id,
        birthday: time,
      });
      this.$parent.$parent.getUserInfo();
      this.$emit("changeShowBirthDayPopup");
    },
    onCancel() {
      this.$emit("changeShowBirthDayPopup");
    },
    onChange() {},
  },
};
</script>
<style scoped>
.box {
  width: 100%;
  height: 100%;
}
</style>
